package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AdditionalVariableAddDTO;
import org.jsola.hr.dto.AdditionalVariableUpdateDTO;
import org.jsola.hr.entity.AdditionalVariableDO;
import org.jsola.hr.query.AdditionalVariableQuery;
import org.jsola.hr.service.IAdditionalVariableService;
import org.jsola.hr.vo.AdditionalVariableVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工自定义信息关联变量
 *
 * @author zhr
 */
@Component
public class AdditionalVariableTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAdditionalVariableService additionalVariableService;

    /**
     * 生成add测试数据
     * @return AdditionalVariableAddDTO
     */
    public AdditionalVariableAddDTO getAdditionalVariableAddDTO(){
        AdditionalVariableAddDTO additionalVariableAddDTO = new AdditionalVariableAddDTO();
        additionalVariableAddDTO.setTemplateId(SafeKit.getLong(getRandomValue("bigint",11)));
        additionalVariableAddDTO.setAdditionalId(SafeKit.getLong(getRandomValue("bigint",11)));
        return additionalVariableAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AdditionalVariableUpdateDTO
     */
    public AdditionalVariableUpdateDTO getAdditionalVariableUpdateDTO(AdditionalVariableVO additionalVariableVO){
        return additionalVariableService.selectDOById(additionalVariableVO.getId(), SITE_ID).to(AdditionalVariableUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AdditionalVariableQuery
     */
    public AdditionalVariableQuery getAdditionalVariableQuery() {
        AdditionalVariableQuery additionalVariableQuery = new AdditionalVariableQuery();
        List<AdditionalVariableDO> additionalVariableDOList = additionalVariableService.list(new AdditionalVariableDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(additionalVariableDOList)) {
            AdditionalVariableDO additionalVariableDO = additionalVariableDOList.get(0);
            additionalVariableQuery = additionalVariableDO.to(AdditionalVariableQuery.class);
        }
        return additionalVariableQuery;
    }

    /**
     * 保存示例
     * @return AdditionalVariableVO
     */
    public AdditionalVariableVO saveAdditionalVariableExample(){
        AdditionalVariableAddDTO addDTO = this.getAdditionalVariableAddDTO();
        AdditionalVariableVO additionalVariableVO = additionalVariableService.save(addDTO,buildTokenUser());
        return additionalVariableVO;
    }


}

